<?php
include "./view/htm/header.inc.htm";
?>

<div class="row">
    <div class="col-lg-6 offset-lg-3">
        <div class="card card-block m-t-1">
            <h4 class="card-title"><?php echo $header['title']; ?>
                <span id="price"><?php echo $conf['wx_mkpr'] ?>枚
			</span></h4>
            <div class="btn-group btn-group-justified" role="group">
                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-secondary checkprice" value="10">
                        10元
                    </button>
                </div>
                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-secondary checkprice" value="20">
                        20元
                    </button>
                </div>
                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-secondary checkprice" value="50">
                        50元
                    </button>
                </div>
                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-secondary checkprice" value="100">
                        100元
                    </button>
                </div>
                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-secondary checkprice" value="200">
                        200元
                    </button>
                </div>
                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-secondary checkprice" value="500">
                        500元
                    </button>
                </div>
            </div>
            <form action="./plugin/xn_wechat_pay/index.php" class="form-inline m-t-2" method="post" id="from">
                <div class="form-group">
                    <label class="sr-only" for="exampleInputAmount">充值金额</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            ¥
                        </div>
                        <input value="10" type="text" name="price" price="<?php echo (int)$conf['wx_mkpr'] ?>"
                               class="form-control" onkeyup="value=value.replace(/[^\d]/g,'')" id="exampleInputAmount">
                        <div class="input-group-addon">
                            .00
                        </div>
                    </div>
                </div>
                <button type="submit" id="submit" class="btn btn-primary">
                    充值
                </button>
            </form>
        </div>
        <div class="card card-block m-t-1">
            <h4 class="card-title">金币余额<?php echo $user['rmbs'] ?>枚</h4>
            <div class="table-responsive">
                <table class="table" style="min-width:520px;">
                    <thead>
                    <tr>
                        <th width="80">单号</th>
                        <th width="80">金额</th>
                        <th width="180">下单时间</th>
                        <th width="180">支付时间</th>
                    </tr>
                    </thead>
                    <tbody id="paylist">
                    <?php if ( !empty( $paylog ) ) {
                        foreach ( $paylog as $_v ) { ?>
                            <tr rid="<?php echo $_v['rid'] ?>">
                                <td><?php echo $_v['rid'] ?></td>
                                <td><?php echo $_v['rmbs'] * 0.01 ?>元</td>
                                <td><?php echo $_v['regdate_fmt'] ?></td>
                                <td><?php echo $_v['paydate_fmt'] ?></td>
                            </tr>
                        <?php }
                    } ?>
                    </tbody>
                </table>
            </div>
            <nav class="text-center m-t-1">
                <ul class="pagination"><?php echo $pagination; ?></ul>
            </nav>
        </div>
        <a role="button" class="btn btn-secondary m-x-auto" href="<?php echo url('my'); ?>">
            <?php echo lang('back'); ?>
        </a>
    </div>
</div>

<?php
include "./view/htm/footer.inc.htm";
?>

<script type="text/javascript">var jpay = $('#pay');
    var jbutton                         = $('button.checkprice');

    jbutton.on('click', function () {
        if ( parseInt($('#exampleInputAmount').attr('price')) < 1 ) {
            $('#price').text('支付未开启');
            jpay.addClass('disabled');
        } else {
            $('#price').text(parseInt($(this).attr('value')) * parseInt($('#exampleInputAmount').attr('price')) + '枚');
            $('#exampleInputAmount').val($(this).attr('value'));
        }
    });

    var jform   = $("#form");
    var jsubmit = $("#submit");
    var referer = '<?php echo http_referer(); ?>';
    jform.on('submit', function () {
        jform.reset();
        jsubmit.button('loading');
        var postdata = jform.serialize();
        $.xpost(jform.attr('action'), postdata, function (code, message) {
            if ( code == 0 ) {
                $.alert(message);
                jsubmit.text(message).delay(2000).button('reset').location(referer);
                return;
            } else {
                $.alert(message);
                jsubmit.button('reset');
            }
        });
        return false;
    });</script>
</body>
</html>